<?php

namespace app\classroom\service;


use app\classroom\model\ClassroomModel;

class ClassroomService
{
    //教室添加
    public function adminClassroom($filter)
    {
        $where=[];
        $join=[];
        $field='a.*';
        $category=empty($filter['category'])?0:intval($filter['category']);
//        var_dump($category);
        if(empty($category)){
//            $where['sc.id']=['eq',$category];
            array_push($join,[
               '__SCHOOL__ sc','sc.id=a.parent_id'
            ]);
            $field='a.*,sc.name as name1,sc.id';
        }else{
            $where['sc.id']=['eq',$category];
            array_push($join,[
                '__SCHOOL__ sc','sc.id=a.parent_id'
            ]);
            $field='a.*,sc.name as name1,sc.id';
        }
//        var_dump($field);
        //cmf_classroom
        $classroomModel=new ClassroomModel();
        $data=$classroomModel->alias('a')->field($field)
                ->join($join)
                ->where($where)
                ->paginate(3);
        return $data;
    }
    //index首页中


}